package cn.itcast.bos.web.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.system.Role;
import cn.itcast.bos.service.RoleService;
import cn.itcast.bos.web.action.common.BaseAction;

@ParentPackage(value="json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class RoleAction extends BaseAction<Role> {

	@Autowired
	private RoleService roleService;
	
	/**
	 * 显示
	 */
	@Action(value = "role_list", results = {@Result(name = "success", type = "json")})
	public String list() {
		// 查询所有的权限数据
		List<Role> list = roleService.findAll();
		
		//放入值栈
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	/**
	 * 添加方法
	 */
	//权限ID
	private String[] permissionIds;
	//菜单ID
	private String menuIds;

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}
	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}
	
	 @Action(value = "role_save", results = {@Result(name = "success", type = "redirect",location="./pages/system/role.html")})
	 public String  save() {
		 //调用业务层,保存角色数据
		 roleService.save(model,permissionIds,menuIds);
		 
		 return SUCCESS;
	 }
	 
}






